function batchRecycle(sUrl, sTip) {
	var value = getChkedValue();
	sUrl += "&id=" + value;
	recycleRefresh(sUrl, sTip);
}

function recycleRefresh(sUrl, sTip) {
	if (confirm(sTip)) {
		sUrl += "&" + new Date().getTime();
		idea.ajax({
			url: sUrl,
			dataType: "json",
			success: function(ret) {
				if (ret.err_no == 0) {
					window.location.reload();
				}
				else {
					showTips(ret.err_msg);
					errTips();
				}
			}
		});
	}
}

function recycle(sUrl, oBtn, sTip) {
	if (confirm(sTip)) {
		sUrl += "&" + new Date().getTime();
		idea.ajax({
			url: sUrl,
			dataType: "json",
			success: function(ret) {
				showTips(ret.err_msg);
				if (ret.err_no == 0) {
					hideTrByBtn(oBtn);
					succTips();
				}
				else {
					errTips();
				}
			}
		});
	}
}

function succTips() {
	idea.id("tips").className = "alert success";
}

function errTips() {
	idea.id("tips").className = "alert error";
}

function showTips(sText) {
	idea.id("tips").innerText = sText;
	idea.id("tips").style.display = "block";
}

function hideTrByBtn(oBtn) {
	var oTr = getTrByBtnName(oBtn.name);
	oTr.style.display = "none";
}

function getTrByBtnName(sBtnName) {
	var oTbody = idea.id("show_list").getElementsByTagName("tbody")[0];
	var oTrs = oTbody.getElementsByTagName("tr");
	var oTds = oBtns = null;
	for (var i in oTrs) {
		if (!idea.isInt(i)) {
			continue;
		}
		
		oTds = oTrs[i].getElementsByTagName("td");
		for (var j in oTds) {
			if (!idea.isInt(j)) {
				continue;
			}
			
			oBtns = oTds[j].getElementsByTagName("input");
			for (var z in oBtns) {
				if (!idea.isInt(z)) {
					continue;
				}
				
				if (oBtns[z].name == sBtnName) {
					return oTrs[i];
				}
			}
		}
	}
	
	return false;
}

function attachToggle() {
	var sType = "checkbox";
	var oTgl = idea.getInput(sType, "toggle");
	var sName = oTgl.value;
	oTgl.onclick = function() {
		idea.chgInputsChked(sType, sName, oTgl.checked);
	}

	var oBoxs = idea.getInputs(sType, sName);
	for (var i in oBoxs) {
		oBoxs[i].onclick = function() {
			oTgl.checked = idea.isInputsChked(sType, sName);
		}
	}
}

function getChkedValue() {
	var sType = "checkbox";
	var oTgl = idea.getInput(sType, "toggle");
	var sName = oTgl.value;
	var chkedValue = idea.getChkedInputsVal(sType, sName);
	return idea.join(",", chkedValue);
}
